mini.parse();

var grid = mini.get("datagrid1");
var arr2=[];
var columns=[
    {field:"id",title:"id",align:"right"},
    {field:"name",title:"名称",align:"right"},

]
var grid = mini.get("datagrid1");
function SetData(data) {
    var data=mini.clone(data);
    console.log(data);
    formId=data.formId;
    menuId=data.menuId;
    //初始刷新
    httpRequest();
}



//请求数据
        function httpRequest(Row) {

            $.ajax({
                url: ajaxUrl + "/formltems/findColumn.do",
                type: 'POST',
                data: {
                    formListId: formId,
                    menuId: menuId
                },
                success: function (data) {
                    var arr2 = data.slice(0, 1);
                    var arr = data.slice(1);
                    console.log(arr);
                    console.log(data);
                    data1 = mini.clone(data);
                    data1 = data1.splice(1)
                    // grid.setData(data1);
                    // if (Row) {
                    //     grid.select(Row, true);
                    // } else {
                    //
                    // }
                    // grid.setData(data);
                    console.log(arr2);
                    console.log(Object.prototype.toString.call(arr2));
                    grid.setData(arr);
                    if (Row){
                        grid.select(Row,true);
                    }else {
                        grid.select(Row,false);
                    }
                },
                error: function (data) {
                    console.log(data);
                    mini.alert("失败");
                }
            })
        }



//关闭页面
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

//顺序调整：向上一行
        function topChange() {
            var topRow = grid.getSelected();
            if (topRow) {
                var btnIdVal = topRow.field;
                console.log(btnIdVal);
                $.ajax({
                    url: ajaxUrl + '/formltems/lastformltems.do',
                    type: 'post',
                    data: {
                        field: btnIdVal
                    },
                    success: function (data) {
                        if (data.state == 'success') {
                            httpRequest(topRow);
                        } else {
                            mini.alert(data.message);
                        }
                    }
                })
            } else {
                mini.alert('请选择需要移动的行');
            }
        }

//顺序调整：向下一行
        function downChange() {
            var topRow = grid.getSelected();
            if (topRow) {
                var btnIdVal = topRow.field;
                console.log(btnIdVal);
                $.ajax({
                    url: ajaxUrl + '/formltems/nextformltems.do',
                    type: 'post',
                    data: {
                        field: btnIdVal
                    },
                    success: function (data) {
                        if (data.state == 'success') {
                            //加载完成后默认选中勾选的行
                            httpRequest(topRow);
                        } else {
                            mini.alert(data.message);
                        }
                    },
                    error: function (message) {
                        mini.alert(message);
                    }
                })
            } else {
                mini.alert('请选择需要移动的行');
            }
        }

//保存按钮
        function save() {
            alert("1")
        }

//保存按钮
        function save() {
            var grid = mini.get("datagrid1");

            var data = grid.getData();
            console.log(Object.prototype.toString.call(data));
            console.log(data);
            console.log(arr2);
            var data = arr2.concat(data);
            var json = mini.encode(data);
            console.log(json);

        }
